<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增借用实验室')"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-hide">
                    <label class="layui-form-label">id</label>
                    <div class="layui-input-block">
                        <input class="layui-input" id="id" th:value="${lab.id}" autocomplete="off" name="id"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">实验室名称</label>
                    <div class="layui-input-block">
                        <input class="layui-input" id="labName" th:value="${lab.labName}" autocomplete="off"
                               name="labName"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">实验室备注</label>
                    <div class="layui-input-block">
                        <input class="layui-input" id="remark" th:value="${lab.remark}" autocomplete="off"
                               name="remark"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">实验室图片</label>
                    <div class="layui-input-block">
                        <div class="layui-upload-drag" id="imgs">
                            <i class="layui-icon"></i>
                            <p>点击上传，或将文件拖拽到此处</p>
                            <div class="layui-hide" id="uploadDemoView">
                                <hr>
                                <img src="" alt="上传成功后渲染" style="max-width: 196px">
                            </div>
                        </div>
                    </div>
                </div>
                <input class="layui-hide" name="image" id="image">
            </div>
        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    layui.use(['form', 'jquery', 'upload'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let upload = layui.upload;

        //拖拽上传
        upload.render({
            elem: '#imgs'
            , url: '/file/upload'
            , accept: 'images'
            , done: function (res) {
                if (res.success) {
                    layer.msg('上传成功');
                    $('#image').val(res.data);
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', '/file/download/' + res.data);
                }
            }
        });

        form.on('submit(user-update)', function (data) {
            $.ajax({
                url: '/lab/manage/update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>